package com.wy.Listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import java.io.Serializable;

public class ActionListener implements HttpSessionActivationListener, Serializable, HttpSessionBindingListener {
    private final String name;

    @Override
    public String toString() {
        return "ActionListener{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        System.out.println(event.getSession()+"添加" + event.getName() + "="+event.getValue());
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        System.out.println(event.getSession()+"移除" + event.getName() + "="+event.getValue());
    }

    public ActionListener(String name) {
        this.name = name;
    }

    @Override
    public void sessionWillPassivate(HttpSessionEvent se) {
        System.out.println(se.getSession().getId());
    }

    @Override
    public void sessionDidActivate(HttpSessionEvent se) {
        System.out.println(se.getSession().getId());
    }
}
